using System;
using System.Collections.Generic;
using System.Text;
using System.Linq;
using DotNetX;

namespace DotNetX.Test
{
    class Program
    {
        static void Main(string[] args)
        {
            try
            {
                Console.WriteLine("The current version of this framework is: {0}\n", AppSettings.VersionAsString);

                // test the indexable string
                TestIndexableString();

                // test the indexable string variant
                TestIndexableStringVariant();

                // test the string type
                TestStringType();
            }
            catch (Exception ex)
            {
                // output the error
                Console.Write(ex.ToString());
            }
            finally
            {
                // wait for input
                Console.ReadKey();
            }
        }

        /// <summary>
        /// This tests the string type
        /// </summary>
        private static void TestStringType()
        {
            // output the header
            Console.WriteLine("\nTesting DotNetX.Strings.StringType...\n");

            // 32-integer
            Console.WriteLine("32-bit integer...");
            Console.WriteLine("Value Test - \"32\": {0}", StringType.IsInt32("32"));
            Console.WriteLine("Value Test - \"This is not an integer\": {0}", StringType.IsInt32("This is not an integer"));
            Console.WriteLine("Value Test - \"111 Test Value 111\": {0}", StringType.IsInt32("111 Test Value 111"));
            Console.WriteLine("Value Test - \"99999999999999\": {0}", StringType.IsInt32("99999999999999"));

            // 64-integer
            Console.WriteLine("\n64-bit integer...");
            Console.WriteLine("Value Test - \"32\": {0}", StringType.IsInt64("32"));
            Console.WriteLine("Value Test - \"This is not an integer\": {0}", StringType.IsInt64("This is not an integer"));
            Console.WriteLine("Value Test - \"111 Test Value 111\": {0}", StringType.IsInt64("111 Test Value 111"));
            Console.WriteLine("Value Test - \"99999999999999\": {0}", StringType.IsInt64("99999999999999"));

            // output success
            Console.WriteLine("\nSuccessfully tested DotNetX.Strings.StringType.\n");
        }

        /// <summary>
        /// This tests the indexable string
        /// </summary>
        /// <returns></returns>
        static private void TestIndexableString()
        {
            // output the header
            Console.WriteLine("\nTesting DotNetX.Strings.IndexableString...\n");

            // create the string
            IndexableString<double> indexableString = new IndexableString<double>();
            indexableString.IndexedString = "value1=3.890&value2=3.890&value3=3.890";

            Console.WriteLine("IndexString: {0}", indexableString.IndexedString);
            Console.WriteLine("IndexString Count: {0}", indexableString.Count);

            Console.WriteLine("Value Test - value1: {0}", indexableString["value1"]);
            Console.WriteLine("Value Test - value2: {0}", indexableString["value2"]);
            Console.WriteLine("Value Test - value3: {0}", indexableString["value3"]);
            Console.WriteLine("Value Test - valuex: {0}", indexableString["valuex"]);

            // output success
            Console.WriteLine("\nSuccessfully tested DotNetX.Strings.IndexableString.\n");
        }

        /// <summary>
        /// This tests the indexable string variant
        /// </summary>
        /// <returns></returns>
        static private void TestIndexableStringVariant()
        {
            // output the header
            Console.WriteLine("\nTesting DotNetX.Strings.TestIndexableStringVarient...\n");

            // create the string
            IndexableStringVariant indexableString = new IndexableStringVariant();
            indexableString.IndexedString = "value1=4&value2=3&value3=p";

            Console.WriteLine("IndexString: {0}", indexableString.IndexedString);
            Console.WriteLine("IndexString Count: {0}", indexableString.Count);

            Console.WriteLine("Value Test - value1: {0}", indexableString["value1", typeof(double)]);
            Console.WriteLine("Value Test - value2: {0}", indexableString["value2", typeof(int)]);
            Console.WriteLine("Value Test - value3: {0}", indexableString["value3", typeof(char)]);
            Console.WriteLine("Value Test - valuex: {0}", indexableString["valuex", typeof(string)]);

            // output success
            Console.WriteLine("\nSuccessfully tested DotNetX.Strings.TestIndexableStringVarient.\n");
        }
    }
}
